# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=nerd-fonts
pkgver=3.1.1
pkgrel=0
pkgdesc="Patched developer targeted fonts with a high number of glyphs"
url="https://nerdfonts.com"
arch="noarch"
license="MIT AND OFL-1.1 AND Apache-2.0"
provides="nerd-fonts-stable=$pkgver-r$pkgrel"
replaces="nerd-fonts-stable"
options="!check"  # no testsuite provided
builddir="$srcdir"

# The following CSV has columns: <id>,<zipname>,<fontname>,<origname>
# <id> is the suffix for the resulting package.
# <fontname> is the name of the file itself.
#
# If <fontname> is empty, <zipname> will be used instead.
# <origname> is used only for pkgdesc and it may be empty.
# "~" will be replaced with a single whitespace.
_fonts="
	anonymous-pro,AnonymousPro,Anonymice,Anonymous~Pro
	arimo,Arimo,,
	bitstrom-wera-sans-mono,BitstreamVeraSansMono,BitstromWeraNerdFontMono,Bitstrom~Wera~Sans~Mono
	cascadia-code,CascadiaCode,CaskaydiaCove,Cascadia~Code
	comic-shanns-mono,ComicShannsMono,ComicShannsMono,Comic~Shanns~Mono
	dejavu-sans-mono,DejaVuSansMono,DejaVuSansM,DejaVu~Sans~Mono
	droid-sans-mono,DroidSansMono,DroidSansM,Droid~Sans~Mono
	fira-code,FiraCode,FiraCode,Fira~Code
	fira-mono,FiraMono,FiraMono,Fira~Mono
	go-mono,Go-Mono,GoMono,Go~Mono
	hack,Hack,,
	hasklig,Hasklig,Hasklug,Hasklig
	hermit,Hermit,Hurmit,Hermit
	ia-writer,iA-Writer,iMWriting,iA~Writer
	ibm-plex-mono,IBMPlexMono,BlexMono,IBM~Plex~Mono
	inconsolata,Inconsolata,,
	jetbrains-mono,JetBrainsMono,JetBrainsMono,JetBrains~Mono
	liberation-mono,LiberationMono,LiterationMono,Liberation~Mono
	meslo,Meslo,,
	monofur,Monofur,Monofur,
	mononoki,Mononoki,Mononoki,
	overpass,Overpass,,
	share-tech-mono,ShareTechMono,ShureTechMono,Share~Tech~Mono
	source-code-pro,SourceCodePro,SauceCodePro,Source~Code~Pro
	space-mono,SpaceMono,SpaceMono,Space~Mono
	terminus,Terminus,Terminess,Terminus
	tinos,Tinos,,
	ubuntu,Ubuntu,,
	ubuntu-mono,UbuntuMono,UbuntuMono,Ubuntu~Mono
	victor-mono,VictorMono,VictorMono,Victor~Mono
	"
_depends_all=""
subpackages="
	nerd-fonts-all:_all
	font-nerd-fonts-symbols:_symbols
	"
source="$pkgname-symbols-$pkgver.tar.xz::https://github.com/ryanoasis/nerd-fonts/releases/download/v$pkgver/NerdFontsSymbolsOnly.tar.xz
	10-nerd-font-symbols-$pkgver.conf::https://raw.githubusercontent.com/ryanoasis/nerd-fonts/v$pkgver/10-nerd-font-symbols.conf
	"
for _font in $_fonts; do
	_pkgname="font-${_font%%,*}-nerd"
	_filename=${_font#*,}; _filename=${_filename%%,*}

	_depends_all="$_depends_all $_pkgname"
	subpackages="$subpackages $_pkgname:_subpackage:noarch"
	source="$source $_pkgname-$pkgver.tar.xz::https://github.com/ryanoasis/nerd-fonts/releases/download/v$pkgver/$_filename.tar.xz"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local id=${subpkgname#font-}; id=${id%-nerd}

	local IFS_OLD=$IFS IFS=','
	set -- $(printf '%s\n' "$_fonts" | grep "^\s*$id," | tr '~' ' ')
	if [ $# -lt 2 ]; then
		error "$id was not found in \$_fonts or wrong entry!"
		return 1
	fi
	IFS=$IFS_OLD

	local fontname=${3:-$2}
	local origname=${4-}
	depends="fontconfig"
	pkgdesc="$fontname Nerd Font${origname:+" (modified $origname Font)"}"

	# for backward compatibility (Alpine <3.16)
	case "$subpkgname" in
		font-ibm-plex-mono-nerd) provides="font-ibm-plex-nerd=$pkgver-r$pkgrel";;
		font-libertion-mono-nerd) provides="font-liberation-nerd=$pkgver-r$pkgrel";;
		font-ubuntu-nerd) depends="$depends font-ubuntu-mono-nerd";;
	esac

	cd "$builddir"
	install -Dm644 ./"$fontname"*.*tf -t "$subpkgdir"/usr/share/fonts/${subpkgname#font-}/
}

_symbols() {
	depends="fontconfig"
	pkgdesc="Nerd Font (Symbols Only)"

	install -Dm644 "$srcdir"/SymbolsNerdFont*.ttf -t "$subpkgdir"/usr/share/fonts/nerd-fonts/
	install -Dm644 "$srcdir"/10-nerd-font-symbols-$pkgver.conf \
		"$subpkgdir"/usr/share/fontconfig/conf.avail/10-nerd-font-symbols.conf
}

_all() {
	pkgdesc="Meta package for all patched Nerd Fonts"
	depends="$_depends_all"

	mkdir -p "$subpkgdir"
}

sha512sums="
0a9eeeff86458463e78f8157014ffd87214ba62a38139f9cff1ef41d6b1006fb64997ffe86e458f75ef699b2794a33d4f328ee1de01cd0ec69b10be74fa634a4  nerd-fonts-symbols-3.1.1.tar.xz
b9703fb721a6b12054954a33338bca6afec5a89f306284ae195aea9812f0091ba908513fc0b867feb8c243ad24015c6aea73b9835f34c8fd39ff2dcbbf25f026  10-nerd-font-symbols-3.1.1.conf
853ab55c94582014154a5ebfc7214bffd901f1b197b07052b578aeb9585e17164626d2609d77ce6e28d50bc7b05f03f18804cfd30a399994288effb06a6ad5d9  font-anonymous-pro-nerd-3.1.1.tar.xz
ba328c53ad3fb4d8bfaca8a7354debff465580ed3b043624865b6165fe95e3550425e2e06dc440818d2285d33bfbfe4d874be3192883984b37fa619aab644c92  font-arimo-nerd-3.1.1.tar.xz
88f0c1e61692342bce4ca16abe57cc09594520171e3276ae6a1907d960ae231389e9817809fa482473a3606ade93ea0118dbd31815baaa2742b43a2f63886549  font-bitstrom-wera-sans-mono-nerd-3.1.1.tar.xz
e89bee382b6d5dbed4996c36281979cfc999f112701c636cbc0a99ebaf7547b5c7e78b5de99d45a55a0caa4674cc20422c637f0ddff460d322373080dfcf345e  font-cascadia-code-nerd-3.1.1.tar.xz
388fe06d1cc1cfbd677712f13921f5570b30a2d0ffcda575d9deb3aedee6ba9276c8ce8eac48bbe6bda951ffe8fda1704d9cd93d9a8e5a63bd3aa727d6af7406  font-comic-shanns-mono-nerd-3.1.1.tar.xz
d119deb13a827898d2e2810a76fea9a63ba5d5777ba179b8dfbdf0a1dbc1e3f3cace42948327a737d28e0fc5061ddc6c86e79b22e049086ea26cc32d213f210b  font-dejavu-sans-mono-nerd-3.1.1.tar.xz
a20f5bccab9af3151ff224dec571d678fb79b90f6e6ceaca6881fc7c2b8ae010c2b290f1973f0628039f2e79063749c72a31d1715d5ce7aa77c914ec8bc076cb  font-droid-sans-mono-nerd-3.1.1.tar.xz
f2fe9eb51e02638ac1fde9bcf6f33914c43fb83ab7027ff1331fe5d98dd0b07aeac027af61f7731a13521db5600eb0fceb56b10d91419f8e30aa8120641d949c  font-fira-code-nerd-3.1.1.tar.xz
6ffd169ba6ceaa761fd799ff0bb40b35f03653ff0527832afa955487058286985d8b39cce7c150e395b7cca9e123253f7a0acb7a28322000971d21c61cddd148  font-fira-mono-nerd-3.1.1.tar.xz
d717984a4c2b54981b74a91c84a59d39eb01b27791e08593af4794d46889b992ea35f13a6bc665afda485bbb1f3101d6b99fb82db17887f4c1268a9b6c53d96b  font-go-mono-nerd-3.1.1.tar.xz
f519605d751df61ca32afc1fa027c05d94c132920acb895acae8afbd524ba0d973a342224e576b78d02ccbf5d409bd8f92e2a952e771880c136c77fb10ee037d  font-hack-nerd-3.1.1.tar.xz
2e7768a66f43c258420029de533f02c7618d43baa091c2dc8a1e364b3ae7b209ef73f1aee87cb6582656c567e814ace275ea2fdc0a5906f3bc6d0dc60188a6bd  font-hasklig-nerd-3.1.1.tar.xz
9aef21e4f4b6db36c2d7c3cb9d33da4f370f0218562f44fdbc2ea7ce07a71157bf9e75994b2638395f6e2460c941156620b0166a6b82efbe1537407f8417dbba  font-hermit-nerd-3.1.1.tar.xz
a0fe57e6071922a92d234b3160e4268b09ce87c966a94d2d2345160c4c54d02b5b1fd83ac80baf5b2a5d304fe4b4e8b15a722edb907b1ec9b889ebe88c739083  font-ia-writer-nerd-3.1.1.tar.xz
5535f2027e8da6d0d5d9ed3d0413e758067457ffa42d7a3f4d569e035c9d6ed1464a1657c510bf97b4e038f30271f2743f318a950bf3ee2b6fe8ab2a26ef7635  font-ibm-plex-mono-nerd-3.1.1.tar.xz
06b478c436222a173bbb569ec9d97e97ceff9fba4111f75c8caf15d40fa77ec1839d08473c171fc95b2fd1f9f853cefa9741afc7d3f0de3e955a0bf862c34669  font-inconsolata-nerd-3.1.1.tar.xz
d0642d40ef5bb6843f789722eb1e9cc8aa8ac55f49516166e37e37b9b626eda842f60e37fc16ff0cc99d98b0a8aedab8870a99355fb3c31749f00fe09d4f589c  font-jetbrains-mono-nerd-3.1.1.tar.xz
a8051ba068a3c1a4ef7726f6eefb173261368fe56232cf5085ca72b0fbafb71e6a5800ae426f06d8d075a673accd4cadf1b7676c4448ab60e642ff2b32f57416  font-liberation-mono-nerd-3.1.1.tar.xz
27614d1fedc652102cbfb400e4a5f662d40d323c3fd514636c84de641f18bd212676efdd8095ade9d6fd6af52694bc455d0cc83421ed00a371493cba930ca493  font-meslo-nerd-3.1.1.tar.xz
e1be74e4d749f424e364a2fda54bd9268c02b36e1ab92ac5efbb3edf9ee0c4277e23c69c4cc85f617994f4bdc5e01d12940d0d4e30a7510d32a734a8ed394a90  font-monofur-nerd-3.1.1.tar.xz
7ed1a582a2a19c83d2f6cc3e8fbed736efd4f0e727564102ce2912df80519cd0d27b5f173ac6e11555832a1748cd384c8a5bf7b1adb9e76eea934035b3c12bc2  font-mononoki-nerd-3.1.1.tar.xz
d626f499e3c4d06dca4224f3b83a37dc6a3e4eb5a9f0aee7a82da5107c30540195a9da0904bb313234f834ce245fdb84c6476c846b87494e23b4540be23dd114  font-overpass-nerd-3.1.1.tar.xz
938916e716b7776c4afd5c002c9ceec629d5b1653d2b6b17e54c2b1ae146bb8d205c74062e23c7a273b7cd4742b13f4359c177a4532481013710cf66ba9f6453  font-share-tech-mono-nerd-3.1.1.tar.xz
eb19120d24daf1e5b47d4e92d32344eab0882a7ee89583ead29a8550a18ae28706aef63ac399d0d2779a3345f7287a83d415956b3888f5859c4c3a26c80d944e  font-source-code-pro-nerd-3.1.1.tar.xz
80757c1f6302c66c635f5860b697b147b4363544957da572e1f815623b96a76b465f35c549f05e7f2ca1170ea78799d305fdc19ddcf9f683af90b4fff93632ff  font-space-mono-nerd-3.1.1.tar.xz
23f1170a887ba7cc7e07dd7715c075e4af7e0ac304a4988694bfd0ac0357c05b4a42f81c772873fb051f62ca77b6a2d36a1fa4d2bf1bd002730f33bcc4ca2e30  font-terminus-nerd-3.1.1.tar.xz
eac42fee6026a178913ff17a0c099bc56012291e997e57d0863f3ceb6319bd735c9e3a513935df92d7c0254afeaa91c977e70ffbd1aab6edd74377cf3fb599f2  font-tinos-nerd-3.1.1.tar.xz
c63ed8d1348cc3752c4d2810fef0ee32b6ed4a3e725b183f21e522a9745f31e5bd9a5fefb969ac4960b63d3a95bc1ee30980de30a826eac1f572c24fb28c48df  font-ubuntu-nerd-3.1.1.tar.xz
326e16008b7ae650ec45f5bb1167362874c2dded0399f7152a50747e4fd09dc135fcae0aa2852e63bf8d956d79a75ab1a4402d57c46711305ad2940f468ee3a5  font-ubuntu-mono-nerd-3.1.1.tar.xz
38fb000374f7ed5e5daf745e29399b481bd0783eb870c59e717054f091e407993d42ffbdb824adff9d6c3c43bcf81c62c75c7bbb0ee361cf996ab28a173b7b45  font-victor-mono-nerd-3.1.1.tar.xz
"
